// 自定义Ui控制台
// @author:wangff8@qq.com  @date:2024-04-16
library UIConsole initializer init requires MathUtil, UnitUtil, UIInit, PropertyUtil, Hero

    globals
        // 经验条的宽度
        constant real EXP_BAR_WIDTH = 430.0 / 2400.0
    endglobals

    // 鼠标进入
    function IEProIcon takes nothing returns nothing
        local integer uid = GetPlayerId(DzGetTriggerUIEventPlayer())
        local integer ui = StringHash("控制台UI")
        local integer i

        local string proStr = "主属性:力量"
        if getUnitPrimaryState(NOW_UNIT[uid]) == 2 then
            set proStr = "主属性:敏捷"
        elseif getUnitPrimaryState(NOW_UNIT[uid]) == 3 then
            set proStr = "主属性:智力"
        endif

        set i = 25
        if DzGetTriggerUIEventFrame() == LoadInteger(UI_HASH, ui, i) then
            call showTipWithPrice(uid, "ReplaceableTextures\\CommandButtons\\BTNFootman.blp", "属性", "|cffccffcc每点力量增加3点生命值|r|n|cffffffcc每1W敏捷增加1%的攻速|r|n|cffcc99ff每1W智力增加1%的技能伤害（最多增加200%）|r|n|cffff9900每点主属性增加0.3攻击|r", proStr, "")
        endif

        set proStr = null
    endfunction
    // 鼠标离开
    function OEProIcon takes nothing returns nothing
        local integer uid = GetPlayerId(DzGetTriggerUIEventPlayer())
        local integer ui = StringHash("控制台UI")
        local integer i

        set i = 25
        if DzGetTriggerUIEventFrame() == LoadInteger(UI_HASH, ui, i) then
            call hideTip(uid)
        endif
    endfunction



    // 重新定义控制UI
    function initConsoleUI takes nothing returns nothing
        local integer ui = StringHash("控制台UI")
        local integer i

        // 创建控制台UI背景
        set i = 0
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("FRAME", "name", DzGetGameUI(), "template", 0))
        // call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "name", DzGetGameUI(), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.18, 0.09 )
        // call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "2222.tga", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 7, DzGetGameUI(), 7, 0, 0.02 )
        call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )

        // 英雄昵称
        set i = 1
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 0), "UI_TEXT_12", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.1, 0.015 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 1, LoadInteger(UI_HASH, ui, 0), 1, 0, 0.005 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "英雄名称" )

        // 经验条
        // 进度
        // 后期增加一个背景
        set i = 2000
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "name", LoadInteger(UI_HASH, ui, 0), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 433.0 / 2400.0, 37.0 / 1800.0 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "bg_exp.tga", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 1, LoadInteger(UI_HASH, ui, 0), 1, 0.002, -0.010 )

        set i = 2
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "name", LoadInteger(UI_HASH, ui, 2000), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.0, 37.0 / 1800.0 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "bg_exp_con.tga", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 2000), 0, 0.0001, 0.0 )

        // 前景框
        set i = 2001
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "name", LoadInteger(UI_HASH, ui, 2000), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 433.0 / 2400.0, 37.0 / 1800.0 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "bg_exp_qk.tga", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 2000), 0, 0.0, 0.0 )

        // 文字
        set i = 3
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 2000), "UI_TEXT_10", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), EXP_BAR_WIDTH, 0.010 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 4, LoadInteger(UI_HASH, ui, 2000), 4, 0, 0.0 )
        // call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 0), 0, 0.02, -0.015 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "等级 1" )
        // 预留一个4给经验条添加边框

        // 攻击
        // 攻击图标
        set i = 5
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "name", LoadInteger(UI_HASH, ui, 0), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.025, 0.025 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "ico_atk.tga", 0 )
        // call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 0), 0, 0.00, -0.032 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 0), 0, 0.02, -0.034 )
        // 攻击文字
        set i = 6
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 5), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.06, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 5), 2, 0.0, -0.002 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "|cffffcc00攻击|r" )
        // 攻击加成
        set i = 7
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 5), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 3, LoadInteger(UI_HASH, ui, 6), 3, 0.015, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "" )
        // 攻击基础值
        set i = 8
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 5), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 6), 6, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "0" )

        // 护甲
        // 护甲图标
        set i = 10
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "name", LoadInteger(UI_HASH, ui, 0), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.025, 0.025 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "ico_hujia.tga", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 1, LoadInteger(UI_HASH, ui, 5), 7, 0.00, -0.004 )
        // 护甲文字
        set i = 11
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 10), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.06, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 10), 2, 0.0, -0.002 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "|cffffcc00护甲|r" )
        // 护甲加成
        set i = 12
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 10), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 3, LoadInteger(UI_HASH, ui, 11), 3, 0.015, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "" )
        // 护甲基础值
        set i = 13
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 10), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 11), 6, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "0" )


        // 属性模块
        // 属性图标
        set i = 15
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "name", LoadInteger(UI_HASH, ui, 0), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.025, 0.025 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "ico_str.tga", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 3, LoadInteger(UI_HASH, ui, 5), 8, 0.06, -0.002 )

        // 按钮
        set i = 25
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BUTTON", "name", LoadInteger(UI_HASH, ui, 15), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.025, 0.025 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 4, LoadInteger(UI_HASH, ui, 15), 4, 0.0, 0.0 )
        // 鼠标进入事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i), 2, "IEProIcon", false)
        // 鼠标离开事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i), 3, "OEProIcon", false)


        // 力量文字
        set i = 16
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 15), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.06, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 6, LoadInteger(UI_HASH, ui, 15), 2, 0.0, 0.008 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "|cffffcc00力量|r" )
        // 力量加成
        set i = 17
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 15), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 3, LoadInteger(UI_HASH, ui, 16), 3, 0.015, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "" )
        // 力量基础值
        set i = 18
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 15), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, 16), 6, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "0" )

        // 敏捷文字
        set i = 19
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 15), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.06, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, i-1), 6, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "|cffffcc00敏捷|r" )
        // 敏捷加成
        set i = 20
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 15), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 3, LoadInteger(UI_HASH, ui, i-1), 3, 0.015, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "" )
        // 敏捷基础值
        set i = 21
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 15), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, i-2), 6, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "0" )

        // 智力文字
        set i = 22
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 15), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.06, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, i-1), 6, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "|cffffcc00智力|r" )
        // 智力加成
        set i = 23
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 15), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 3, LoadInteger(UI_HASH, ui, i-1), 3, 0.015, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "" )
        // 智力基础值
        set i = 24
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 15), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, i-2), 6, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "0" )


        // 血量遮层
        set i = 30
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "name", DzGetGameUI(), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.078, 0.028 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "UI\\169x60_压底.tga", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 1, DzFrameGetPortrait(), 7, 0.00, 0.00 )

        // 血量文字
        set i = 31
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 30), "UI_TEXT_8", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.078, 0.014 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 1, LoadInteger(UI_HASH, ui, 30), 1, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "0/0" )

        // 魔法文字
        set i = 32
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 30), "UI_TEXT_8", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.078, 0.014 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 7, LoadInteger(UI_HASH, ui, 30), 7, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "0/0" )

        // 生命值加成
        set i = 33
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, 30), "UI_TEXT_8_LEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 0.05, 0.01 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i), 0, LoadInteger(UI_HASH, ui, i-3), 2, 0.0, 0.0 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "" )
    endfunction

    // 隐藏控制台UI
    function hideConsoleUI takes nothing returns nothing
        local integer ui

        // 隐藏控制台
        //隐藏三围
        call DzFrameSetAbsolutePoint( DzSimpleFontStringFindByName( "InfoPanelIconHeroStrengthLabel", 6), 4, 0.40, 0.40)
        //隐藏攻击
        call DzFrameSetAbsolutePoint( DzSimpleFontStringFindByName( "InfoPanelIconLabel", 0), 4, 0.40, 0.40)
        //隐藏护甲
        call DzFrameSetAbsolutePoint( DzSimpleFontStringFindByName( "InfoPanelIconLabel", 2), 4, 0.40, 0.40)
        //隐藏三围图标
        call DzFrameSetAbsolutePoint( DzSimpleTextureFindByName( "InfoPanelIconHeroIcon", 6), 4, 0.40, 0.40)
        //隐藏攻击图标
        call DzFrameSetAbsolutePoint( DzSimpleTextureFindByName( "InfoPanelIconBackdrop", 0), 4, 0.40, 0.40)
        //隐藏护甲图标
        call DzFrameSetAbsolutePoint( DzSimpleTextureFindByName( "InfoPanelIconBackdrop", 2), 4, 0.40, 0.40)

        // 隐藏经验条
        set ui = DzSimpleFrameFindByName("SimpleHeroLevelBar", 0)
        call DzFrameClearAllPoints( ui )
        call DzFrameSetPoint( ui, 0, DzGetGameUI(), 0, -0.80, -0.030 / 2 )
        call DzFrameSetSize( ui, 1/1920*0.8, 1/1080*0.6 )
        // 隐藏英雄称谓(经验条上面的)
        set ui = DzSimpleFontStringFindByName("SimpleClassValue", 0)
        call DzFrameClearAllPoints( ui )
        call DzFrameSetPoint( ui, 0, DzGetGameUI(), 0, -0.80, -0.030 / 2 )
        call DzFrameSetSize( ui, 1/1920*0.8, 1/1080*0.6 )
        // 上面英雄名称
        set ui = DzSimpleFontStringFindByName("SimpleNameValue", 0)
        call DzFrameClearAllPoints( ui )
        call DzFrameSetPoint( ui, 0, DzGetGameUI(), 0, -0.80, -0.030 / 2 )
        call DzFrameSetSize( ui, 1/1920*0.8, 1/1080*0.6 )
    endfunction

    // 设置经验条的进度（value传入百分比0.1表示10%）
    function setExpBarProgress takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local real width = EXP_BAR_WIDTH * value
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, 2), width, 0.020555 )
    endfunction

    // 设置经验条的文本
    function setExpBarText takes integer uid, string text returns nothing
        local integer ui = StringHash("控制台UI")
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 3), text )
    endfunction

    // 设置控制台英雄名称
    function setCsHeroName takes integer uid, string name returns nothing
        local integer ui = StringHash("控制台UI")
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 1), name )
    endfunction

    // 设置控制台属性图标
    function setCsAttributeIcon takes integer uid, integer attribute returns nothing
        local integer ui = StringHash("控制台UI")

        // 1表示力量  2表示敏捷  3表示智力
        if Player(uid) == GetLocalPlayer() then
            if attribute == 1 then
                call DzFrameSetTexture( LoadInteger(UI_HASH, ui, 15), "ico_str.tga", 0 )
            elseif attribute == 2 then
                call DzFrameSetTexture( LoadInteger(UI_HASH, ui, 15), "ico_agi.tga", 0 )
            elseif attribute == 3 then
                call DzFrameSetTexture( LoadInteger(UI_HASH, ui, 15), "ico_int.tga", 0 )
            endif
        endif

    endfunction

    // 设置控制台攻击力加成
    function setCsAttackPower takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = R2S(keepDecimal(value*100.0 + 0.001, 1))
        set v = SubString(v, 0, StringLength(v)-2)
        set v = "|cffffcc00攻击:|r|cff00ff00" + v + "%|r"
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 6), v )
        set v = null
    endfunction

    // 设置控制台护甲值加成
    function setCsArmorPower takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = R2S(keepDecimal(value*100.0 + 0.001, 1))
        set v = SubString(v, 0, StringLength(v)-2)
        set v = "|cffffcc00护甲:|r|cff00ff00" + v + "%|r"
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 11), v )
        set v = null
    endfunction

    // 设置控制台力量加成
    function setCsStrengthPower takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = R2S(keepDecimal(value*100.0 + 0.001, 1))
        set v = SubString(v, 0, StringLength(v)-2)
        set v = "|cffffcc00力量:|r|cff00ff00" + v + "%|r"
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 16), v )
        set v = null
    endfunction

    // 设置控制台敏捷加成
    function setCsAgilityPower takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = R2S(keepDecimal(value*100.0 + 0.001, 1))
        set v = SubString(v, 0, StringLength(v)-2)
        set v = "|cffffcc00敏捷:|r|cff00ff00" + v + "%|r"
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 19), v )
        set v = null
    endfunction

    // 设置控制台智力加成
    function setCsIntelligencePower takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = R2S(keepDecimal(value*100.0 + 0.001, 1))
        set v = SubString(v, 0, StringLength(v)-2)
        set v = "|cffffcc00智力:|r|cff00ff00" + v + "%|r"
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 22), v )
        set v = null
    endfunction

    // 设置控制台生命值加成
    function setCsSMZPower takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = R2S(keepDecimal(value*100.0 + 0.001, 1))
        set v = SubString(v, 0, StringLength(v)-2)
        set v = "|cff00ff00" + v + "%|r"
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 33), v )
        set v = null
    endfunction

    // 设置控制台攻击基础值
    function setCsAttackValue takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = "0"

        if value > 10000.0 then
            set v = R2S(keepDecimal(value / 10000.0, 1))
            set v = SubString(v, 0, StringLength(v)-2)
            set v = v + "万"
        else
            set v = I2S(R2I(value))
        endif

        call DzFrameSetText( LoadInteger(UI_HASH, ui, 8), v )

        set v = null
    endfunction

    // 设置控制台护甲基础值
    function setCsArmorValue takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = "0"

        if value > 10000.0 then
            set v = R2S(keepDecimal(value / 10000.0, 1))
            set v = SubString(v, 0, StringLength(v)-2)
            set v = v + "万"
        else
            set v = I2S(R2I(value))
        endif

        call DzFrameSetText( LoadInteger(UI_HASH, ui, 13), v )
        set v = null
    endfunction

    // 设置控制台力量基础值
    function setCsStrengthValue takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = "0"

        if value > 10000.0 then
            set v = R2S(keepDecimal(value / 10000.0, 1))
            set v = SubString(v, 0, StringLength(v)-2)
            set v = v + "万"
        else
            set v = I2S(R2I(value))
        endif

        call DzFrameSetText( LoadInteger(UI_HASH, ui, 18), v )
        set v = null
    endfunction

    // 设置控制台敏捷基础值
    function setCsAgilityValue takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = "0"

        if value > 10000.0 then
            set v = R2S(keepDecimal(value / 10000.0, 1))
            set v = SubString(v, 0, StringLength(v)-2)
            set v = v + "万"
        else
            set v = I2S(R2I(value))
        endif
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 21), v )
        set v = null
    endfunction

    // 设置控制台智力基础值
    function setCsIntelligenceValue takes integer uid, real value returns nothing
        local integer ui = StringHash("控制台UI")
        local string v = "0"

        if value > 10000.0 then
            set v = R2S(keepDecimal(value / 10000.0, 1))
            set v = SubString(v, 0, StringLength(v)-2)
            set v = v + "万"
        else
            set v = I2S(R2I(value))
        endif
        call DzFrameSetText( LoadInteger(UI_HASH, ui, 24), v )
        set v = null
    endfunction

    // 设置控制台生命
    function setCsLifeValue takes integer uid, real value1, real value2 returns nothing
        local string v1 = "0"
        local string v2 = "0"

        if value1 > 100000000.0 then
            set v1 = R2S(keepDecimal(value1 / 100000000.0, 1))
            set v1 = SubString(v1, 0, StringLength(v1)-1)
            set v1 =  v1 + "亿"
        elseif value1 > 10000.0 then
            set v1 = R2S(keepDecimal(value1 / 10000.0, 1))
            set v1 = SubString(v1, 0, StringLength(v1)-2)
            set v1 =  v1 + "万"
        else
            set v1 = I2S(R2I(value1))
        endif

        if value2 > 100000000.0 then
            set v2 = R2S(keepDecimal(value2 / 100000000.0, 1))
            set v2 = SubString(v2, 0, StringLength(v2)-1)
            set v2 =  v2 + "亿"
        elseif value2 > 10000.0 then
            set v2 = R2S(keepDecimal(value2 / 10000.0, 1))
            set v2 = SubString(v2, 0, StringLength(v2)-2)
            set v2 =  v2 + "万"
        else
            set v2 = I2S(R2I(value2))
        endif

        call DzFrameSetText( LoadInteger(UI_HASH, StringHash("控制台UI"), 31), v1 + "/" + v2 )
        set v1 = null
        set v2 = null
    endfunction

    // 设置控制台魔法值
    function setCsManaValue takes integer uid, real value1, real value2 returns nothing
        // call BJDebugMsg(R2S(value1) + " - " + R2S(value2))
        call DzFrameSetText( LoadInteger(UI_HASH, StringHash("控制台UI"), 32), I2S(R2I(value1)) + "/" + I2S(R2I(value2)) )
    endfunction

    // 显示单位无敌控制台样式
    function showUnitInvincibleConsoleUI takes integer uid returns nothing
        local integer ui = StringHash("控制台UI")
        local integer i

        // 隐藏经验条
        set i = 2000
        call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )

        // 隐藏攻击属性
        set i = 5
        call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )

        // 隐藏属性
        set i = 15
        call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )

        // 护甲显示无敌
        set i = 11
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "|cffffcc00护甲:|r" )
        set i = 13
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "  |cffff0000无敌的|r" )

    endfunction

    // 显示单位控制台样式无属性
    function showUnitConsoleUI takes integer uid returns nothing
        local integer ui = StringHash("控制台UI")
        local integer i

        set i = 15
        call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )
    endfunction

    // 刷新控制台UI数据
    function refreshConsoleUI takes nothing returns nothing
        local integer uid = GetPlayerId(GetLocalPlayer())
        local integer ui = StringHash("控制台UI")
        local integer i

        local integer level 
        local integer exp
        local integer needExp

        if NOW_UNIT[uid] != null then

            // 显示UI
            call DzFrameShow( LoadInteger(UI_HASH, ui, 0), true )
            set i = 2000
            call DzFrameShow( LoadInteger(UI_HASH, ui, i), true )
            set i = 5
            call DzFrameShow( LoadInteger(UI_HASH, ui, i), true )
            set i = 15
            call DzFrameShow( LoadInteger(UI_HASH, ui, i), true )

            // 刷新数据
            // 显示英雄名称
            if FF_GetUnitName(NOW_UNIT[uid]) == null then
                call setCsHeroName(uid, GetUnitName(NOW_UNIT[uid]))
            else
                call setCsHeroName(uid, FF_GetUnitName(NOW_UNIT[uid]))
            endif

            // 经验条
            set level = GetUnitLevel(NOW_UNIT[uid])
            set exp = GetHeroXP(NOW_UNIT[uid])
            set needExp = getLevelNeedExp(level + 1)
            if heroLevelNeedExp[level + 1] > 0 then
                call setExpBarProgress(uid, I2R(exp - getLevelNeedExp(level)) / I2R(heroLevelNeedExp[level + 1]))
                // 经验条文本
                call setExpBarText(uid, "等级 " + I2S(level) + "("+ I2S(exp) + "/" + I2S(needExp) +")")
            endif

            // 攻击
            call setCsAttackValue(uid, FF_GetAttack(NOW_UNIT[uid]))
            // 护甲
            call setCsArmorValue(uid, FF_GetArmor(NOW_UNIT[uid]))
            // 力量
            call setCsStrengthValue(uid, FF_GetStr(NOW_UNIT[uid]))
            // 敏捷
            call setCsAgilityValue(uid, FF_GetAgi(NOW_UNIT[uid]))
            // 智力
            call setCsIntelligenceValue(uid, FF_GetInt(NOW_UNIT[uid]))

            // 生命值
            call setCsLifeValue(uid, FF_GetHp(NOW_UNIT[uid]), FF_GetMaxHp(NOW_UNIT[uid]))
            // 魔法值
            call setCsManaValue(uid, GetUnitState( NOW_UNIT[uid], UNIT_STATE_MANA), GetUnitState( NOW_UNIT[uid], UNIT_STATE_MAX_MANA))

            if GetUnitTypeId(NOW_UNIT[uid]) == GetUnitTypeId(udg_player_select_hero[uid]) and GetPlayerId(GetOwningPlayer(NOW_UNIT[uid])) == uid then
                // // 攻击加成
                // call setCsAttackPower(uid, udg_add_dtbfb_atk[uid])
                // // 力量加成
                // call setCsStrengthPower(uid, udg_add_dtbfb_qsxll[uid])
                // // 护甲加成
                // call setCsArmorPower(uid, udg_add_dtbfb_hj[uid])
                // // 敏捷加成
                // call setCsAgilityPower(uid, udg_add_dtbfb_qsxmj[uid])
                // // 智力加成
                // call setCsIntelligencePower(uid, udg_add_dtbfb_qsxzl[uid])
                // // 生命值加成
                // call setCsSMZPower(uid, udg_add_dtbfb_smz[uid])

                // 攻击加成
                call setCsAttackPower(uid, FF_GetAddition_Attack(NOW_UNIT[uid]))
                // 力量加成
                call setCsStrengthPower(uid, FF_GetAddition_Str(NOW_UNIT[uid]))
                // 护甲加成
                call setCsArmorPower(uid, FF_GetAddition_Armor(NOW_UNIT[uid]))
                // 敏捷加成
                call setCsAgilityPower(uid, FF_GetAddition_Agi(NOW_UNIT[uid]))
                // 智力加成
                call setCsIntelligencePower(uid, FF_GetAddition_Int(NOW_UNIT[uid]))
                // 生命值加成
                call setCsSMZPower(uid, FF_GetAddition_Hp(NOW_UNIT[uid]))
            else
                call DzFrameSetText( LoadInteger(UI_HASH, ui, 6), "|cffffcc00攻击:|r" )
                call DzFrameSetText( LoadInteger(UI_HASH, ui, 11), "|cffffcc00护甲:|r" )
                call DzFrameSetText( LoadInteger(UI_HASH, ui, 16), "|cffffcc00力量:|r" )
                call DzFrameSetText( LoadInteger(UI_HASH, ui, 19), "|cffffcc00敏捷:|r" )
                call DzFrameSetText( LoadInteger(UI_HASH, ui, 22), "|cffffcc00智力:|r" )
                call DzFrameSetText( LoadInteger(UI_HASH, ui, 33), "" )
                // 隐藏经验条
                set i = 2000
                call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )
            endif

            // 如果是普通单位，隐藏属性显示
            if FF_IsNormalUnit(NOW_UNIT[uid]) then
                // 隐藏属性
                set i = 15
                call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )
                // 隐藏经验条
                set i = 2000
                call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )
            endif

            // 如果单位没有攻击方式，隐藏攻击
            if NOW_UNIT[uid] != udg_player_select_hero[uid] then
                if YDWEGetObjectPropertyInteger(YDWE_OBJECT_TYPE_UNIT, GetUnitTypeId(NOW_UNIT[uid]), "weapsOn") == 0 then
                    set i = 5
                    call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )
                endif
            endif

            if GetUnitAbilityLevel(NOW_UNIT[uid], 'Avul') >= 1 then
                // 显示无敌控制台
                set i = 13
                call DzFrameSetText( LoadInteger(UI_HASH, ui, i), "  |cffff0000无敌的|r" )
            endif

        else
            // 隐藏UI
            call DzFrameShow( LoadInteger(UI_HASH, ui, 0), false )
        endif
    endfunction

    // 控制原生位置调整
    private function setBtnPosition takes nothing returns nothing
        local integer ydul_nA
        local integer ydul_nB
        set ydul_nA = 0
        loop
            exitwhen ydul_nA > 5
            call DzFrameClearAllPoints( DzFrameGetItemBarButton(ydul_nA) )
            call DzFrameSetSize( DzFrameGetItemBarButton(ydul_nA), 0.03, 0.03 )
            set ydul_nA = ydul_nA + 1
        endloop
        call DzFrameSetPoint( DzFrameGetItemBarButton(0), 4, DzGetGameUI(), 6, 0.532, 0.0955 )
        call DzFrameSetPoint( DzFrameGetItemBarButton(1), 4, DzGetGameUI(), 6, 0.5705, 0.0955 )
        call DzFrameSetPoint( DzFrameGetItemBarButton(2), 4, DzGetGameUI(), 6, 0.532, 0.0565 )
        call DzFrameSetPoint( DzFrameGetItemBarButton(3), 4, DzGetGameUI(), 6, 0.5705, 0.0565 )
        call DzFrameSetPoint( DzFrameGetItemBarButton(4), 4, DzGetGameUI(), 6, 0.532, 0.0215 )
        call DzFrameSetPoint( DzFrameGetItemBarButton(5), 4, DzGetGameUI(), 6, 0.5705, 0.0215 )
        set ydul_nA = 0
        loop
            exitwhen ydul_nA > 2
            set ydul_nB = 0
            loop
                exitwhen ydul_nB > 3
                call DzFrameClearAllPoints( DzFrameGetCommandBarButton(ydul_nA, ydul_nB) )
                call DzFrameSetSize( DzFrameGetCommandBarButton(ydul_nA, ydul_nB), 0.03, 0.03 )
                set ydul_nB = ydul_nB + 1
            endloop
            set ydul_nA = ydul_nA + 1
        endloop
        call DzFrameSetPoint( DzFrameGetCommandBarButton(0, 0), 4, DzGetGameUI(), 6, 0.6585, 0.093 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(0, 1), 4, DzGetGameUI(), 6, 0.6945, 0.093 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(0, 2), 4, DzGetGameUI(), 6, 0.7295, 0.093 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(0, 3), 4, DzGetGameUI(), 6, 0.7655, 0.093 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(1, 0), 4, DzGetGameUI(), 6, 0.6585, 0.0575 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(1, 1), 4, DzGetGameUI(), 6, 0.6945, 0.0575 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(1, 2), 4, DzGetGameUI(), 6, 0.7295, 0.0575 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(1, 3), 4, DzGetGameUI(), 6, 0.7655, 0.0575 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(2, 0), 4, DzGetGameUI(), 6, 0.6585, 0.0215 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(2, 1), 4, DzGetGameUI(), 6, 0.6945, 0.0215 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(2, 2), 4, DzGetGameUI(), 6, 0.7295, 0.0215 )
        call DzFrameSetPoint( DzFrameGetCommandBarButton(2, 3), 4, DzGetGameUI(), 6, 0.7655, 0.0215 )

        call DestroyTimer( GetExpiredTimer() )
    endfunction

    // 设置小地图位置
    private function setMapPosition takes nothing returns nothing
        local integer ydul_nA
        call DzFrameSetPoint( DzFrameGetMinimap(), 6, DzGetGameUI(), 6, 0.003, 0.004 )
        call DzFrameSetPoint( DzFrameGetMinimap(), 2, DzGetGameUI(), 6, 0.123, 0.116 )
        set ydul_nA = 0
        loop
            exitwhen ydul_nA > 4
            call DzFrameClearAllPoints( DzFrameGetMinimapButton(ydul_nA) )
            set ydul_nA = ydul_nA + 1
        endloop
    endfunction

    private function init takes nothing returns nothing

        local timer t = CreateTimer()
        call TimerStart(t, 0.0, false, function setBtnPosition)

        call setMapPosition()
        
        // 隐藏控制台
        call hideConsoleUI()

        // 重新定义控制台UI
        call initConsoleUI()

        set t = null
    endfunction
endlibrary


